package org.iks.push.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.iks.common.constant.Constant;
import org.iks.common.pojo.message.Message;
import org.iks.push.serial.SerializableType;

/**
 * Author kzou
 * Date 2024/1/28
 * Description: JSON消息类型处理器
 */
public class JsonWebSocketFrameHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception {
        String text = msg.text();
        Message message = SerializableType.JSON.deserialize(text.getBytes(Constant.Utf8));
        if (message == null) {
            // 未匹配
            super.channelActive(ctx);
        }
        ctx.fireChannelRead(message);
    }

}
